package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.CommissionKvDto;
import com.ymatou.iapi.productmanager.parameter.QueryProductCommissionsBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.QueryProductCommissionsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
*批量查询商品平台佣金
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_QueryProductCommissions{
	private static QueryProductCommissionsBean queryproductcommissionsBean;
	private static QueryProductCommissionsCall queryproductcommissionsCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("globalSellerId"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询商品平台佣金(全球优先业务下架)");
	}

	@Before
	public void caseUp() {
		queryproductcommissionsBean=new QueryProductCommissionsBean();
		queryproductcommissionsCall=new QueryProductCommissionsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryproductcommissionsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryProductCommissions_001() {
		Logger.start(true,"批量查询商品平台佣金");
		try {
			AddSellerProductRequest addSellerProductRequest = ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addSellerProductRequest).get("Data").getAsJsonObject().get("ProductId").getAsString();
            BigDecimal commission = new BigDecimal(10.00);
            ProductManagerCallServiceV2.UpdateProductCommision(addSellerProductRequest.getSellerId(),productId,addSellerProductRequest.getSellerName(),commission);
			List<String> productIds = Arrays.asList(productId);
            queryproductcommissionsBean.setProductIds(productIds);
			queryproductcommissionsCall.setData(queryproductcommissionsBean);
			queryproductcommissionsCall.callService();			
			Logger.verifyEquals("200",queryproductcommissionsCall.getString("Code"),"验证Code");
			queryproductcommissionsCall.getCommissionList().forEach(p->{
				Logger.verifyEquals(productId,p.getProductId(),"验证productId");
				Logger.verifyEquals(commission.intValue(),p.getProductCommission().intValue(),"验证commission");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryProductCommissions_002() {
		Logger.start(true,"批量查询商品平台佣金，多商品");
		try {
			AddSellerProductRequest addSellerProductRequest = ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(sellerId);
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addSellerProductRequest).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addSellerProductRequest).get("Data").getAsJsonObject().get("ProductId").getAsString();
			BigDecimal commission1 = new BigDecimal(10.00);
			BigDecimal commission2 = new BigDecimal(8.00);
			ProductManagerCallServiceV2.UpdateProductCommision(addSellerProductRequest.getSellerId(),productId1,addSellerProductRequest.getSellerName(),commission1);
			ProductManagerCallServiceV2.UpdateProductCommision(addSellerProductRequest.getSellerId(),productId2,addSellerProductRequest.getSellerName(),commission2);
			List<String> productIds = Arrays.asList(productId1,productId2);
			queryproductcommissionsBean.setProductIds(productIds);
			queryproductcommissionsCall.setData(queryproductcommissionsBean);
			queryproductcommissionsCall.callService();
			Logger.verifyEquals("200",queryproductcommissionsCall.getString("Code"),"验证Code");
			List<CommissionKvDto> commissionKvDtos = queryproductcommissionsCall.getCommissionList();
			commissionKvDtos.forEach(p->{
				if (p.getProductId().equals(productId1)){
					Logger.verifyEquals(commission1.intValue(),p.getProductCommission().intValue(),"验证commission1");
				}else{
					Logger.verifyEquals(commission2.intValue(),p.getProductCommission().intValue(),"验证commission1");
				}
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryProductCommissions_003() {
		Logger.start(true,"批量查询商品平台佣金,商品不存在");
		try {
			List<String> productIds = Arrays.asList("hwqiojwdohfi");
			queryproductcommissionsBean.setProductIds(productIds);
			queryproductcommissionsCall.setData(queryproductcommissionsBean);
			queryproductcommissionsCall.callService();
			Logger.verifyEquals("201",queryproductcommissionsCall.getString("Code"),"验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}